//
// Created by 15229 on 2021/11/21.
//

#ifndef SYSTEM_R23_NATIVE_SYNCBUFFER_H
#define SYSTEM_R23_NATIVE_SYNCBUFFER_H

#include <utils/RefBase.h>
#include <semaphore.h>

namespace android {
class IMemory;

class SyncBuffer : public RefBase {
public:
    SyncBuffer(size_t size, const char *name = nullptr);
    SyncBuffer(sp<IMemory>& mem);

    bool lock();
    bool unlock();

    void* addr(size_t *len = nullptr);

    sp<IMemory> getMemory() { return mMem; }
private:
    ~SyncBuffer();

    sem_t *_lock = nullptr;
    sp<IMemory> mMem = nullptr;
    //uint32_t mBufferId = -1;
};
}


#endif //SYSTEM_R23_NATIVE_SYNCBUFFER_H
